package cn.classTest.mall.controller;

import cn.classTest.mall.domain.Mall;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.MallService;
import com.github.pagehelper.PageInfo;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/mall")
public class MallController {

    @Autowired
    private MallService mallService;


    @RequiresPermissions(value = {"mall:list", "商城列表"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo) {
        PageInfo<Mall> query = mallService.query(qo);
        model.addAttribute("pageInfo", query);
        return "mall/list";
    }


    @RequiresPermissions(value = {"mall:input", "商城编辑"}, logical = Logical.OR)
    @RequestMapping("/input")
    public String input(Model model, Long id) {
        if (id != null) {
            Mall mall = mallService.selectOne(id);
            model.addAttribute("mall", mall);
        }
        return "mall/input";
    }


    @RequiresPermissions(value = {"mall:saveOrUpdate", "商城新增或编辑"}, logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Mall mall) {
        mallService.saveOrUpdate(mall);
        return "redirect:/mall/list";
    }

    @RequiresPermissions(value = {"mall:delete", "商城删除"}, logical = Logical.OR)
    @RequestMapping("/delete")
    public String delete(Long id) {
        mallService.delete(id);
        return "redirect:/mall/list";
    }

}
